package com.ihm.labyrinth.bodies;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;

public class Canon extends LabObject {

	private int powerShoot = 15;
	
	protected static Bitmap bitmap;
	
	private int shootCycle;
	
	private int shootCounter;
	
	private RectF shooterBox;
	
	public static enum Direction {Top, Bottom, Right, Left};
	
	private Direction directionCanon = Direction.Right;
	
	public Canon(RectF boundingBox, RectF shooterBox, int shootCycle) {
		super(boundingBox);
		this.shooterBox = shooterBox;
		shootCounter = 0;
		this.shootCycle = shootCycle;
		this.setColor(Color.CYAN);
		
		setTextureSource();
		
	}
	
	private void setTextureSource() {
		switch (this.directionCanon) {
		case Top : source = new Rect(0, 128, 64, 192);
			break;
			
		case Bottom : source = new Rect(64, 128, 128, 192);
			break;
		
		case Right : source = new Rect(128, 128, 192, 192);
			break;
		
		case Left : source = new Rect(192, 128, 256, 192);
			break;

		}
		
	}

	public void resetCounter(){
		shootCounter = 0;
	}
	
	public boolean shoot(){
		return shootCounter > shootCycle;
	}

	public int getShootCycle() {
		return shootCycle;
	}

	public void setShootCycle(int shootCycle) {
		this.shootCycle = shootCycle;
	}
	
	@Override
	public void update(RectF newBoundingBox) {
		super.update(this.boundingBox);
		
		if(shootCounter > shootCycle)
			 shootCounter = 0;
		else
			shootCounter++;
	}

	public RectF getShooterBox() {
		return shooterBox;
	}

	public void setShooterBox(RectF shooterBox) {
		this.shooterBox = shooterBox;
	}

	public Direction getDirectionCanon() {
		return directionCanon;
	}

	public void setDirectionCanon(Direction directionCanon) {
		this.directionCanon = directionCanon;
		setTextureSource();
	}

	public int getPowerShoot() {
		return powerShoot;
	}

	public void setPowerShoot(int powerShoot) {
		this.powerShoot = powerShoot;
	}

}
